package lc;

public class Q718 {

    public int findLength(int[] A, int[] B) {
        // 寻找可优化的地方
        // dp[i][j] = dp[i+1][j+1]+1 or 0
        int dp[][] = new int[A.length+1][B.length+1];
        int ans = 0;
        for (int i = A.length - 1; i >= 0; i--) {
            for (int i1 = B.length - 1; i1 >= 0; i1--) {
                dp[i][i1] = A[i] == B[i1] ? dp[i+1][i1+1] + 1: 0;
                ans = Math.max(dp[i][i1], ans);
            }
        }
        return ans;
    }
}
